<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>医嘱管理</title>
		<link rel="stylesheet" type="text/css" href="lib/layui/css/layui.css" />
		<!-- <link rel="stylesheet" type="text/css" href="css/yzgl.css" /> -->
		<link rel="stylesheet" type="text/css" href="css/reset.css" />
	</head>
	<body>
		<div class="layui-tab layui-tab-brief" lay-filter="demo">
			<ul class="layui-tab-title">
				<li class="layui-this">长期医嘱</li>
				<li>临时医嘱</li>
			</ul>
			<div>
			<!-- 表格 -->
			<table id="demo" lay-filter="list"></table>
			<!-- 表格操作 -->
			<script type="text/html" id="titleTpl">
				<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
				<a class="layui-btn layui-btn-xs" lay-event="stop">停止</a>
				<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">作废</a>
			</script>
			<!-- 分页 -->
			<div id="test2"></div>
	</body>
	<script src="js/jquery-3.3.1.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
	<script src="js/global.js" type="text/javascript" charset="utf-8"></script>
	<!-- <script src="./js/yzlb.js" type="text/javascript" charset="utf-8"></script> -->
	<script type="text/javascript">
		layui.use(['laypage', 'form', 'element', 'table','laytpl', 'util'], function() {
			var laytpl = layui.laytpl;
			var element = layui.element;
			var laypage = layui.laypage;
			var form = layui.form;
			var table = layui.table;
			var util = layui.util;
  
			// 默认参数
			var odc = "2",page="1";
			
			// 监听tab
			element.on('tab(demo)', function(data) {
				console.log(data.index+1);
				odc = data.index+1;
				doctorAdvicesearchList(odc)
			});

			function doctorAdvicesearchList(odc,page) {
				// 请求参数
				var param = JSON.stringify({
					"body": {
						"ordCategory": odc,
						"ordStatus": 1,
						"ordType": 1,
						"currPage": page,
						"pageSize": 10
					}
					// ,
					// "header": {},
					// "token": {}
				});
				$.ajax({
					'type': 'post',
					'url': '/service-nursingwork/doctorAdvice/searchList',
					'data': param,
					'dataType': 'json',
					'contentType': "application/json",
					'success': function(data) {
						console.log(data);
						var len = data.data.length-1;
						var list = data.data.list;
						
						//表格
						table.render({
							elem: '#demo',
							height: 515,
							//toolbar: '#toolbarDemo',
							page: true, //一次请求全部数据前端自动分页
							cols: [
								[
									{field:'ord_type',title:'医嘱类型'},
									{field:'ord_create_time',title:'下达时间',templet: function(d) {
										return util.toDateString(d.create_time * 1000, "yyyy-MM-dd HH:mm:ss")
									}},
									{field:'ord_xtime',title:'停嘱时间',templet: function(d) {
										return util.toDateString(d.create_time * 1000, "yyyy-MM-dd HH:mm:ss")
									}},
									{field:'arcim_desc',title:'医嘱内容'},
									{field:'instr',title:'途径'},
									{field:'phfreq',title:'频率'},
									{field:'ord_user',title:'开嘱医生'},
									{field:'ord_status',title:'医嘱状态'},
									{field:'ord_start_time',title:'执行时间',templet: function(d) {
										return util.toDateString(d.create_time * 1000, "yyyy-MM-dd HH:mm:ss")
									} },
									{field:'title',title:'文章标题',width:200,templet:'#titleTpl'}
								]
							],
							data: data.data
						});
						
						
					},
					'error': function(res) {
						console.log(res);
					}
				});
			}

			doctorAdvicesearchList(odc,page)
			
			//监听行工具事件
			table.on('tool(list)', function(obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
				console.log(obj.data);
				var data = obj.data //获得当前行数据
					,
					layEvent = obj.event; //获得 lay-event 对应的值
				if (layEvent === 'detail') {
					// layer.msg('查看操作');
					
					// 跳转详情...
					console.log(obj.data.source_id);
					window.location.href = "./doctoradvice/advicedetail.html?id=" + obj.data.source_id;
				} else if (layEvent === 'del') {
					layer.confirm('是否确定作废此条医嘱', function(index) {
						obj.del(); //删除对应行（tr）的DOM结构
						layer.close(index);
						//向服务端发送指令
					});
				} else if (layEvent === 'stop') {
					layer.confirm('是否确定停止此条医嘱', function(index) {
						obj.del(); //删除对应行（tr）的DOM结构
						layer.close(index);
						//向服务端发送指令
					});
					
				}
			});
		})
	</script>
</html>
